package com.liu.blindBox.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liu.blindBox.entity.vo.BlindBoxInfoVO;
import com.liu.blindBox.service.BlindBoxService;
import com.liu.common.entity.Result;
import com.liu.common.entity.StatusCode;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/blindBox")
public class BlindBoxController {

    @Resource
    private BlindBoxService blindBoxService;
    
    /**
     * 查询所有盲盒
     */
    @CrossOrigin(origins = "http://localhost:8080", maxAge = 3600)
    @GetMapping("/queryBlindBox")
    public Result queryBlindBox(@RequestParam(value = "key", required = false) String keyword,@RequestParam(value = "blindBoxType", required = false) String blindBoxType,@RequestParam("pageNum")String pageNum, @RequestParam("pageSize")String pageSize){
        PageHelper.startPage(Integer.parseInt(pageNum),Integer.parseInt(pageSize));
        List<BlindBoxInfoVO> blindBoxInfoVOS = blindBoxService.queryBlindBoxInfo(keyword,blindBoxType);
        return new Result(true, StatusCode.OK,"查询成功",new PageInfo<>(blindBoxInfoVOS));
    }

    /**
     * 查询热门盲盒
     */
    @CrossOrigin(origins = "http://localhost:8080", maxAge = 3600)
    @GetMapping("/queryHotBlindBox")
    public Result queryBlindBoxInfoBySaleNum(@RequestParam(value = "key", required = false) String keyword,@RequestParam("pageNum")String pageNum, @RequestParam("pageSize")String pageSize){
        PageInfo<BlindBoxInfoVO> blindBoxInfoVOS = blindBoxService.queryBlindBoxInfoBySaleNum(keyword,pageNum,pageSize);
        return new Result(true, StatusCode.OK,"查询成功",blindBoxInfoVOS);
    }

    /**
     * 根据id查询盲盒信息
     */
    @CrossOrigin(origins = "http://localhost:8080", maxAge = 3600)
    @GetMapping("/queryBlindBoxInfoById")
    public Result queryBlindBoxInfoById(@RequestParam("blindBoxId") String blindBoxId){
        BlindBoxInfoVO blindBoxInfoVO = blindBoxService.queryBlindBoxInfoById(blindBoxId);
        return new Result(true, StatusCode.OK,"查询成功",blindBoxInfoVO);
    }

    /**
     * 查询热门推荐盲盒
     */
    @CrossOrigin(origins = "http://localhost:8080", maxAge = 3600)
    @GetMapping("/queryHotDollBlindBox")
    public Result queryHotDollBlindBox(){
        List<BlindBoxInfoVO> blindBoxInfoVOS = blindBoxService.queryHotDollBlindBoxBySaleNum();
        return new Result(true, StatusCode.OK,"查询成功",blindBoxInfoVOS);
    }
}
